<?php

$columns = Cms()->Column()->getArray();

if ($columns && $columns['children']) {
    foreach ($columns['children'] as $column) {
        if ($column['type'] != 'url') {
            Route::set([
                [
                    'uri' => "/{$column['name']}",
                    'param' => array('id' => $column['id']),
                    'module' => 'Cms',
                    'controller' => 'Article',
                    'action' => 'index',
                ],
                [
                    'uri' => "/{$column['name']}/page/id/(<id>)",
                    'bind' => ['id' => '\d+'],
                    'module' => 'Cms',
                    'controller' => 'Article',
                    'action' => 'page',
                ],
            ]);
        }
        if ($column['children']) {
            foreach ($column['children'] as $key => $children_column) {
                if ($children_column['type'] != 'url') {
                    Route::set([
                        [
                            'uri' => "/{$column['name']}/{$children_column['name']}",
                            'param' => array('id' => $children_column['id']),
                            'module' => 'Cms',
                            'controller' => 'Article',
                            'action' => 'index',
                        ],
                    ]);
                }
            }
        }
    }
}